﻿
function IsEmailNoPostfix(data) {
    if (data == undefined || data.trim() == "") return false;
    if (!/^[0-9a-zA-Z]+(\.[0-9a-zA-Z]+)?$/.test(data)) {
        return false;
    }
    return true;
}

function IsEmailHasPostfix(data, split) {
    if (data == undefined || data.trim() == "") return false;
    var result = true;
    var emailRegex = /^[0-9a-zA-Z]+(\.[0-9a-zA-Z]+)?@@([0-9a-zA-Z]{2,10})(\.[a-zA-Z]{2,10}){1,3}$/;
    if (split == undefined || split == "") {
        if (!emailRegex.test(data)) {
            result = false;
        }
    } else {
        var array = data.split(split);
        var notEmptyArray = new Array();
        for (var i = 0; i < array.length; i++) {
            if (array[i].trim() != "") notEmptyArray.push(array[i]);
        }
        for (var i = 0; i < notEmptyArray.length; i++) {
            if (!emailRegex.test(array[i])) {
                result = false;
                break;
            }
        }
        if (notEmptyArray.length < 1) result = false;
    }
    return result;
}

function IsNullOrEmpty(data) {
    if (data == null || data == undefined || data.trim() == "") {
        return true;
    }
    return false;
}

function ValidateEmail(data) {
    var reg = /^\w+((\.\w+)|(-\w+))?@[A-Za-z0-9]+((.|-)[A-Za-z0-9]+)(\.[A-Za-z0-9]+)?$/g;
    if (reg.test(data)) return true;
    return false;
}

function ValidatePhone(data) {
    var isPhone = /^(\+?0?(1|[0-9]{2,3}))?1[0-9]{10}$/g;//手机号
    var isMob = /^(0?[0-9]{2,3}-?)?[0-9]{7,8}$/g;//座机号
    if (isPhone.test(data) || isMob.test(data)) return true;
    return false;
}

/*----------分割线之上是数据校验、分割线之下是格式转换----------*/

//转换日期格式(时间戳转换为datetime格式)
function getFormatDate(value, format) {
    if (format == null) {
        format = "yyyy-MM-dd hh:mm:ss";
    }
    var date = new Date(value);
    return new Date(value).format(format)
}

Date.prototype.format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1,                   //月份 
        "d+": this.getDate(),                        //日 
        "h+": this.getHours(),                       //小时 
        "m+": this.getMinutes(),                     //分 
        "s+": this.getSeconds(),                     //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds()                  //毫秒 
    };
    if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        }
    }
    return fmt;
}